package com.sykj.bsc.wsy.service.impl;

import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.sykj.bsc.util.JedisUtil;
import com.sykj.bsc.util.Tools;
import com.sykj.bsc.wsy.mapper.Bis_coupon_activeMapper;
import com.sykj.bsc.wsy.model.Bis_coupon_active;
import com.sykj.bsc.wsy.model.Bis_coupon_record;
import com.sykj.bsc.wsy.service.Bis_coupon_activeService;
import com.sykj.bsc.zjj.bean.Bis_custom_user;
@Service
public class Bis_coupon_activeServiceImpl implements Bis_coupon_activeService{
    @Autowired
	private Bis_coupon_activeMapper mapper;
	@Override
	public List<Map> selectBis_coupon_active(Bis_coupon_active active) {
		return mapper.selectBis_coupon_active(active);
	}
	@Override
	public List<Bis_coupon_record> selectBis_coupon_record(Bis_coupon_record record){
		return mapper.selectBis_coupon_record(record);
		
	}
	@Override
	public void deleteBis_coupon_active(int active_id){
		mapper.deleteBis_coupon_active(active_id);
	}
	@Override
	public void insertBis_coupon_active(Bis_coupon_active active) {
		mapper.insertBis_coupon_active(active);
		Set<String> cdKeySet=Tools.createCdkey(active.getBeauty_num(),10);
		   Iterator<String> it = cdKeySet.iterator();
	       while(it.hasNext()){
	    	   Bis_coupon_record record=new Bis_coupon_record();
	    	   record.setMobile(active.getMobile());
	    	   record.setActive_id(active.getActive_id());
	    	   record.setCdkey(it.next());
	    	   mapper.saveCouponRecord(record);
	       }  
	}
	
	/**
	 * 判断产生的美妍币是否失效
	 */
	public void taskCheckIsOld(){
		int beautyNum=Integer.valueOf(JedisUtil.getString("beautyNum","0"));
		int hasDay=Integer.valueOf(JedisUtil.getString("hasDay","0"));
		List<Bis_coupon_record> list=mapper.selectOldRecord(hasDay);
		if(list!=null&&list.size()>0){
			for(Bis_coupon_record record:list){
				mapper.updateRecordStatus(record.getRecord_id());
			}
		}
	}
	
	
	/**
	 * 创建人：迟磊
	 * 用途：获取用户姓名及用户号
	 */
	public List<Bis_custom_user> selectBis_custom_user(){
		return mapper.selectBis_custom_user();
	};
}
